; ======================================================================
; *** Progress Indication Window 1.6 (PIW) ***
; By }RB-338{ / MakSoft Inc.
; Relase date: 31/07/1999
;
; *** Fixes since version 1.00:
; - window is now centered
; - test-driving slowed down
; - centered the progress bar
; - %blah is now removed after the test-drive
; - centered the percentage
; - removed the load event code
; - uses only 1 window
; - added right-click menu to close the window
; - added support for multiple instances
; - added a bit more documentation :-)
; - added 'subtitle'
; - fixed bug: meter dissapearing when changing the title
; - fixed compatibility bug: changed window names from @P.* to @^Pbar.*

; *** Usage:
; 1. Use ^pbar <window name> <description> to open the window.
; 2. Use ^pdraw <window name> <percentage> <subtitle> to input the percentage and (optional) the subtitle.
;
; - Example:
;
; on *:load:{
;   ^pbar load Loading script...		Open the progress window
;   ^pdraw load 0			Sets the percentage to 0%
;   (tasks)				Tasks to do (can be anything)
;   ^pdraw load 20 Loading aliases	Sets the percentage to 20% and the subtitle to 'Loading aliases'
;   ^pbar load Loading script part 2...	Changes the description to 'Loading script part 2...' (you see the changes after changing the percentage)
; }
;
; Test the meter: type /^pbartest
;
; Used vars:
; - %blah
; - %^tmp
; ======================================================================

; Start of PIW Source code

alias ^pbar {
  var %^tmp @^Pbar. $+ $1
  if $window(%^tmp) == $null {
    window -dahkop +esLf %^tmp $int($calc(($window(-1).w - 300) / 2)) $int($calc(($window(-1).h - 100) / 2)) 300 100
    drawrect -frn %^tmp $rgb(face) 7 0 0 300 100
    if ($2 != $null) drawtext -nr %^tmp $rgb(text) "ms sans serif" 20 $calc(150 - $width($2-,ms sans serif,20,1,0) / 2) 5 $2-
    drawdot %^tmp
  }
  else {
    drawrect -frn %^tmp $rgb(face) 7 0 0 300 30
    drawtext -nr %^tmp $rgb(text) "ms sans serif" 20 $calc(150 - $width($2-,ms sans serif,20,1,0) / 2) 5 $2-
  }
}

alias ^pdraw {
  var %^tmp @^Pbar. $+ $1
  if (($window(%^tmp) == $null) || ($2 > 100) || ($2 < 0)) halt
  drawrect -frn %^tmp $rgb(face) 7 9 30 282 50
  drawtext -nro %^tmp $rgb(text) "verdana" 14 $calc((135 - $width($int($2) $+ %,verdana,14,1,0) / 2) + 9) 50 $int($2) $+ %
  drawrect -nif %^tmp 1 0 9 50 $int($calc($2 * 2.7)) 15
  if ($3 != $null) drawtext -nr @^Pbar. $+ $1 $rgb(text) "ms sans serif" 12 $calc(150 - $width($3-,ms sans serif,12,1,0) / 2) 30 $3-
  drawdot %^tmp
  if ($2 == 100) .timer 1 1 window -c %^tmp
}

alias ^pbartest {
  ^pbar test Progress bar test
  var %blah 0
  :loop
  inc %blah 0.1
  ^pdraw test %blah
  if (%blah == 100) goto end
  goto loop
  :end
  halt
}

menu @^Pbar.* {
  Close:window -c $active
}

